package org.jeecg.modules.website.controller.web;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.website.entity.WebSchoolTeacher;
import org.jeecg.modules.website.entity.WebWebsiteMenu;
import org.jeecg.modules.website.entity.WebWorkFile;
import org.jeecg.modules.website.service.IWebSchoolTeacherService;
import org.jeecg.modules.website.service.IWebWorkFileService;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @Description: 学校信息表
 * @Author: jeecg-boot
 * @Date:   2024-08-02
 * @Version: V1.0
 */
@Api(tags="网站API-教师信息相关接口")
@RestController
@RequestMapping("/api/web/webSchoolTeacher")
@Slf4j
public class WebSchoolTeacherApiController extends JeecgController<WebSchoolTeacher, IWebSchoolTeacherService> {
    @Autowired
    private IWebSchoolTeacherService webSchoolTeacherService;


    /**
     * 分页列表查询
     *
     * @param webSchoolTeacher
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "教师信息表-分页列表查询")
    @ApiOperation(value="教师信息表-分页列表查询", notes="教师信息表-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<WebSchoolTeacher>> queryPageList(WebSchoolTeacher webSchoolTeacher,
                                                         @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                         @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                         HttpServletRequest req) {
        QueryWrapper<WebSchoolTeacher> queryWrapper = QueryGenerator.initQueryWrapper(webSchoolTeacher, req.getParameterMap());
        Page<WebSchoolTeacher> page = new Page<WebSchoolTeacher>(pageNo, pageSize);
        queryWrapper.lambda().select(WebSchoolTeacher.class, i -> !i.getProperty().equals("update_time"));
        queryWrapper.eq("publish_status",1); // 只查询已发布的
        queryWrapper.last(" order by publish_time desc"); // 根据发布时间排序
        IPage<WebSchoolTeacher> pageList = webSchoolTeacherService.page(page, queryWrapper);
        return Result.OK(pageList);
    }


    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "教师信息表-通过id查询")
    @ApiOperation(value="教师信息表-通过id查询", notes="教师信息表-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<WebSchoolTeacher> queryById(@RequestParam(name="id",required=true) String id) {
        WebSchoolTeacher webSchoolTeacher = webSchoolTeacherService.getById(id);
        if(webSchoolTeacher==null) {
            return Result.error("未找到对应数据");
        }
        // 每加载一次 阅读量+1
        webSchoolTeacher.setReadNum(webSchoolTeacher.getReadNum()+1);
        webSchoolTeacherService.updateById(webSchoolTeacher);
        return Result.OK(webSchoolTeacher);
    }

    //@AutoLog(value = "教师信息表-通过id查询")
    @ApiOperation(value="教师信息表-通过专业对应id查询", notes="教师信息表-通过专业对应id查询")
    @GetMapping(value = "/queryByMainId")
    public Result<List<WebSchoolTeacher>> queryByMainId(@RequestParam(name="mainId",required=true) String mainId) {
        List<WebSchoolTeacher> webSchoolTeacherList = webSchoolTeacherService.queryByMainId(mainId);
        return Result.OK(webSchoolTeacherList);
    }
}
